/*
 * @Author : Genustin
 * @Date   : 2012-05-31
 * 装箱子
 * 箱子6*6*h, 物品h*1*1, h*2*2, ... h*6*6
 * 给出各种规格物品的数量，求解最少装几箱
 */
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX3 4  //(6*6)/(3*3)
#define MAX2 9  //(6*6)/(2*2)
#define MAX1 36 //(6*6)

int main()
{
	int n1, n2, n3, n4, n5, n6;
	int count;
	int left;
	int remain;
	cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6;
	while (n1+n2+n3+n4+n5+n6 != 0)
	{
		count = n6 + n5 + n4;
		if (n2 > n4*5) {
			n2 -= n4*5;
			n1 = max(n1 - n5*11, 0); 
		} else {
			n1 = max(n1 - n5*11 - 4*(n4*5-n2), 0);
			n2 = 0;
		}
		if (n3 > 0)
		{
			count += n3 / MAX3;
			remain = n3 % MAX3;
			switch(remain){
			case 1:
				left = 5;
				++count;
				break;
			case 2:
				left = 3;
				++count;
				break;
			case 3:
				left = 1;
				++count;			
				break;
			default:
				left = 0;
				break;
			}
			if (left > 0) {
				if (n2 > left) {
					n1 = max(n1 - (6*6 - remain*9 - left*4), 0); 
					n2 -= left;
				} else {
					n1 = max(n1 - (6*6 - remain*9 - n2*4), 0); 
					n2 = 0;
				}
			}			
		}
		if (n2 > 0) 
		{
			count += n2 / MAX2;
			remain = n2 % MAX2;
			if (remain > 0) {
				++count;
				n1 = max(n1 - (6*6 - remain*4), 0);
			}
		}
		if (n1 > 0)
		{
			count += n1 / MAX1;
			if (n1 % MAX1 > 0) {
				++count;
			}
		}
		cout << count << endl;
		cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6;
	}	
	return 0;
}